﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Caching;
namespace ECommerce.DAO.Cache.Productos
{
    public static class Package
    {
        public static ECommerce.Model.Productos.Package GetPackageById(Int32 Id)
        {
            ECommerce.Model.Productos.Package Package = new ECommerce.Model.Productos.Package();
            try
            {
                Package = (ECommerce.Model.Productos.Package)HttpRuntime.Cache["Package-" + Id.ToString()];
            }
            catch (Exception ex)
            {
                Package = null;
            }
            if (Package!=null && Package.Id == 0)
                Package = null;
            return Package;
        }

        public static int SetPackage(ECommerce.Model.Productos.Package Package)
        {
            try
            {
                HttpRuntime.Cache.Insert("Package-" + Package.Id.ToString(), Package);
            }
            catch (Exception ex)
            {
            }
            return Package.Id;
        }
        public static int DelPackage(ECommerce.Model.Productos.Package Package)
        {
            try
            {
                HttpRuntime.Cache.Remove("Package-" + Package.Id.ToString());
            }
            catch (Exception ex)
            {
            }
            return Package.Id;
        }
        //Hacer los metodos para los items de un itemcarrito

        public static ECommerce.Model.Productos.Package[] GetPackagesByIdProducto(int IdProducto)
        {
            ECommerce.Model.Productos.Package[] Packages;
            try
            {
                Packages = (ECommerce.Model.Productos.Package[])HttpRuntime.Cache["PackagesByIdProducto-" + IdProducto.ToString()];
            }
            catch (Exception ex)
            {
                Packages = null;
            }
            if (Packages != null)
                if (Packages.Length == 0)
                    Packages = null;
            return Packages;
        }
        public static void SetPackagesByIdProducto(ECommerce.Model.Productos.Package[] Packages, int IdProducto)
        {
            try
            {
                HttpRuntime.Cache.Insert("PackagesByIdProducto-" + IdProducto.ToString(), Packages);
            }
            catch (Exception ex)
            {
            }
        }
        public static int DelPackagesByIdProducto(int IdProducto)
        {
            try
            {
                HttpRuntime.Cache.Remove("PackagesByIdProducto-" + IdProducto.ToString());
            }
            catch (Exception ex)
            {
            }
            return IdProducto;
        }

        public static ECommerce.Model.Productos.Package[] GetPackages()
        {
            ECommerce.Model.Productos.Package[] Packages;
            try
            {
                Packages = (ECommerce.Model.Productos.Package[])HttpRuntime.Cache["Packages"];
            }
            catch (Exception ex)
            {
                Packages = null;
            }
            if (Packages != null)
                if (Packages.Length == 0)
                    Packages = null;
            return Packages;
        }
        public static void SetPackages(ECommerce.Model.Productos.Package[] Packages)
        {
            try
            {
                HttpRuntime.Cache.Insert("Packages", Packages);
            }
            catch (Exception ex)
            {
            }
        }
        public static void DelPackages()
        {
            try
            {
                HttpRuntime.Cache.Remove("Packages");
            }
            catch (Exception ex)
            {
            }
        }
    }
}
